<template>
	<view class="contener">

		<skeleton :skeleton="skeleton" :loading="loading">
			<block>
				<view class="contenerBox">
					<!-- 轮播图 -->
					<view class="uni-margin-wrap">
						<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :current="current"
							:interval="interval" @change="(e)=>current = e.detail.current">
							<swiper-item class="swiper-item" v-if="video" style="width: 100%;">
								<video class="swiperimg" style="height: 100%;" :src="video"
									enable-progress-gesture="false" mode="heightFix"></video>
							</swiper-item>
							<swiper-item class="swiper-item" style="width: 100%;" v-for="(item,index) in imgData"
								:key="index">
								<image class="swiperimg" :src='item' @click="clickImg" mode="heightFix"></image>
							</swiper-item>
						</swiper>
					</view>

					<view class="bottomCont">
						<view class="cont">
							<view class="topIntro" :style="{top:current==0?'-25rpx':'-50rpx'}">
								<view class="left">
									<view class="leftTop">
										<text class="littleMon">￥</text>
										{{params.minPrice}}
								 	</view>
									<view class="leftBottom">参与限时拼团，获得返现</view>
								</view>
								<view class="right">
									<view class="rightTop">
										最多可返现
									</view>
									<view class="rightBot">
										<text>{{params.returnMax}}</text>元
									</view>
								</view>
							</view>

							<view class="biaotiBox ">
								{{item.title}}
							</view>
							<view class="priceTit">
								<view class="color">
									<text class="littleMon">￥</text> {{item.originalPrice}}
									<text style="color: #b1b1b1;font-size: 10px;margin-left: 15rpx;">原价</text>
								</view>
								<view>
									<text class="sale" style="text-decoration: none;font-size: 30rpx;color: #949393;">
										已拼{{item.sale}}
									</text>
								</view>
							</view>
							<!-- 参与拼团 -->
							<view class="bulk" v-if="orderList.length!=0">
								<view class="bulkTit">
									<view class="titTop textOver">
										限时拼团活动火热进行中...
									</view>
								</view>
								<swiper class="peopleSwiper" @change="changePeople" duration="500" autoplay
									:current="swiperPeople" vertical>
									<swiper-item v-for="(item, index) in orderList" :key="index" style="width: 100rpx;">
										<view class="bulkCont">
											<view class="contLeft">
												<image class="imgView" :src="item.avatar" mode="aspectFill"></image>
												{{item.nick}}
											</view>
											<view class="contRight">
												<button type="default" @click="tzwoyaozhongOrder">去拼单</button>
											</view>
										</view>
										<view class="bulkCont" v-if="orderList[index+1].avatar!=undefined">
											<view class="contLeft">
												<image class="imgView" :src="orderList[index+1].avatar"
													mode="aspectFill"></image>
												{{orderList[index+1].nick}}
											</view>
											<view class="contRight">
												<button type="default" @click="tzwoyaozhongOrder">去拼单</button>
											</view>
										</view>
										<view class="bulkCont" v-if="orderList[index+2].avatar!=undefined">
											<view class="contLeft">
												<image class="imgView" :src="orderList[index+2].avatar"
													mode="aspectFill"></image>
												{{orderList[index+2].nick}}
											</view>
											<view class="contRight">
												<button type="default" @click="tzwoyaozhongOrder">去拼单</button>
											</view>
										</view>
									</swiper-item>
								</swiper>

								<!-- <view class="bulkCont">
									<view class="contLeft">
										<image src="../../static/images/growVegetables/pay_icon.png" mode=""></image>
										陈一套
									</view>
									<view class="contRight">
										<button type="default">去参团</button>
									</view>
								</view> -->
							</view>



							<!-- 地址 -->
							<view class="bulk">
								<view class="bulkTit">
									<view class="titLeft textOver">
										商家信息
									</view>
								</view>
								<view class="bulkCont ">
									<view class="contLeft textSize">
										<view class="image" style="margin-bottom: 20rpx;">
											<image :src="imgapi+shopInfo.storeAvatar" mode=""></image>
										</view>
										<view class="textOver"
											style="margin-left: 100rpx;width: 80%;margin-top: 20rpx;">
											<!-- <view>电话: {{shopInfo.phone}}</view> -->
											<view class="adress">店铺名称: {{shopInfo.storeName}}</view>
										</view>

									</view>
									<view class="contRight">
										<!-- <button type="default" class="btn" @tap="callphone">致电</button> -->
									</view>
								</view>
							</view>

							<view class="">
								<view><text>简介:</text> <text class="overview"> {{item.overview}}</text></view>
							</view>
						</view>
					</view>

					<view class="line"></view>
					<view @click="goEvaList()" style="margin-bottom: 20rpx;">
						<uni-evaluate :list-data="evaList" :rate="rate" />
					</view>
					<view class="shopDetails">
						<view class="shopTitle">
							商品详情
						</view>
						<view class="center_horizontal" style="width:750rpx;padding-bottom: 150rpx;">
							<view class="informationBox2">
								<view>
									<view style="margin-bottom:15rpx;">
										<rich-text :nodes="item.content"></rich-text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>

				<!-- 弹窗 -->
				<hqs-popup :title="item.title" v-model="showPopup" :showHeader="false" :height="popHeight">
					<view class="desc futext" style="font-size: 35rpx;padding-bottom: 150rpx;">
						<view class="topPop">
							<image :src="imgapi+item.avatar" mode="" @click="clickImg(imgapi+item.avatar)"></image>
							<view class="right">
								<view>
									<text>￥</text>{{params.showPrice}}
									<!-- 展示价不等于原价才展示 -->
									<text class="origin"
										v-show="params.showPrice != params.originalPrice">￥{{params.originalPrice}}</text>

									<!--v-if="this.product.inventory === -1 || this.product.inventory > this.form.amount "-->
									<view class="introTit" v-if="isDiscounts">
										<view class="" v-show="params.showTit !== 1 && params.showTit !== 0 ">
											任意用户再买<text
												class="introColor">{{params.poorNum}}</text>{{params.unit}}，即可返现<text
												class="introColor">{{Math.floor((params.backMoney * params.count) * 100) / 100}}</text>元
										</view>
										<view class="" v-show="params.showTit==1">
											当前已是最优惠价格，总共帮您节省<text
												class="introColor">{{Math.floor((params.maxDiscounts * params.count) * 100) / 100}}</text>元
										</view>
									</view>
								</view>
								<!-- <view ><text>￥</text>1-2</view> -->
							</view>
						</view>


						<view class="selectCont" v-if="params.hasSpec==1">
							<view class="line" style="height: 5rpx;"></view>
							<view class="selectName">规格</view>
							<view class="tagSelect">
								<uni-data-checkbox @change="specSelect" mode="tag" v-model="params.specSelect"
									:localdata="speicArr" selectedColor='#70971c' selectedTextColor="#fff">
								</uni-data-checkbox>
							</view>
						</view>

						<view class="line" style="height: 5rpx;"></view>
						<view class="selectCont" v-if="params.hasBuyUnit===1">
							<view class="selectName">可选数量/重量</view>
							<view class="tagSelect">
								<uni-data-checkbox @change="numSelect()" mode="tag" multiple max="1"
									v-model="params.numSelect" :localdata="numArr" selectedColor='#70971c'
									selectedTextColor="#fff">
								</uni-data-checkbox>
							</view>
						</view>
						<view class="selectCont between">
							<view class="selectName">购买数量</view>
							<view style="width: 32%;padding: 10rpx 30rpx;">
								<numSelect model="1" @getValue="count" @addNum="add" @minusNum="minus" color="#9cd53f"
									:value="params.count" :size="60"></numSelect>
							</view>
						</view>

						<view class="selectCont">
							<view class="line" style="height: 5rpx;"></view>
							<view class="selectName">收货方式</view>
							<view class="tagSelect">
								<uni-data-checkbox @change="buySelect" mode="tag" v-model="params.packBuy"
									:localdata="buyArr" selectedColor='#70971c' selectedTextColor="#fff">
								</uni-data-checkbox>
							</view>
							<text style="font-size:30rpx;display: block;
              margin: 20rpx 0 0 20rpx;color: #3eab78" v-if="isMethodPrompt">
								此选项会有专员联系您上门配送哦~
							</text>
						</view>
						<view class="selectCont" v-show="params.packBuy == 1 ">
							<view class="selectName">配送方式</view>
							<view class="tagSelect">
								<view class="packIntro" v-if="params.hasFreeShipp == 1">包邮</view>
								<view class="packIntro" v-else>不包邮</view>
							</view>
						</view>
						<view class="selectCont" v-show="params.packBuy == 0 ">
							<view class="selectName">提货地址</view>
							<view class="tagSelect">
								<view class="packIntro">{{item.selfMentionAddress}}</view>
								<button type="default" size="mini" class="btn" @tap="handleMapLocation">导航</button>
							</view>
						</view>


						<button @tap="goDetail" type="warn" class="btnPop">马上抢</button>
					</view>
				</hqs-popup>

				<!-- 单独买弹窗 -->
				<!-- <hqs-popup :title="item.title" v-model="showPopupAlone" :showHeader="false" :height="popHeight">
					<view class="desc futext" style="font-size: 35rpx;padding-bottom: 150rpx;">
						<view class="topPop">
							<image :src="imgapi+item.avatar" mode="" @click="clickImg(imgapi+item.avatar)"></image>
							<view class="right">
								<view v-if="discountPrice"><text>￥</text>{{discountPrice}}
								</view>
								<view v-else><text>￥</text>{{minOri}}-{{maxOri}}</view>
							</view>
						</view>
						<view class="line" style="height: 5rpx;"></view>
						<view class="selectCont" v-if="params.hasSpec==1">
							<view class="line" style="height: 5rpx;"></view>
							<view style="margin: 20rpx 0;">规格</view>
							<view class="tagSelect">
								<uni-data-checkbox @change="selectPop3" mode="tag" v-model="value" :localdata="speicArr"
									selectedColor='#a0e223' selectedTextColor="#fff">
								</uni-data-checkbox>
							</view>
						</view>
						<button @tap="goDetail(1)" type="warn" class="btnPop">马上抢</button>
					</view>
				</hqs-popup> -->

				<!-- 底部按钮 -->
				<!-- <view class="shopBottomBox">
					<button class="sharebox" open-type="share">分享</button>
					<view @tap="tzwoyaozhongOrder" class="zhaibox" style="background-color: #86cc14;color: #fff;">
						<view style="display: inline-block;margin-top: -15rpx;">￥{{params.minPrice}}</view>
						<view style="display: inline-block;margin-top: -60rpx;">参与拼单</view>
					</view>
				</view> -->
				<view class="goods-carts">
					<uni-goods-nav :options="options" :fill="true" :button-group="customButtonGroup1" @click="onClick"
						@buttonClick="buttonClick" />
				</view>



			</block>
		</skeleton>
	</view>

</template>

<script>
	import cartcontrol from '@/components/cartcontrol.vue'
	import Skeleton from '@/components/ls-skeleton/ls-skeleton.nvue';
	import hqsPopup from "@/components/hqs-popup/hqs-popup.vue"
	import numSelect from '@/pageA/uni_modules/poiuy-numSelect/numSelect.vue'
	import {
		hiddenPhone
	} from "@/utils/auth.js"
	import returnGoods from "../afterSales/returnGoods";
	import uniEvaluate from '../../components/xiujun-evaluate/uni-evaluate.vue';
	export default {
		components: {
			uniEvaluate,
			cartcontrol,
			Skeleton,
			hqsPopup,
			numSelect
		},
		data() {
			return {
				rate: "",
				evaList: [],
				// 优惠提示
				isDiscounts: false,
				// 配送提示
				isMethodPrompt: false,
				city: '',
				// 底部栏
				options: [{
						icon: 'icon-fenxiangfangshi',
						text: '分享'
					},
					{
						icon: 'icon-custom-service',
						text: '客服',
					},
					// {
					// 	icon: 'icon-dianpufill',
					// 	text: '店铺',
					// }
				],
				customButtonGroup1: [{
					text: '立即购买',
					backgroundColor: 'linear-gradient(90deg, #7bba0d, #a9ec28)',
					color: '#fff'
				}],
				orderList: [],
				placeholder: '开始输入...',
				avatarUrl: '',
				nickName: '大苏打',
				indicatorDots: true,
				current: 0, //当前轮播位置
				autoplay: false,
				interval: 2000,
				duration: 2000,
				item: {}, //merchantGroupGoods信息
				imgData: [],
				usEvaluate: false,
				clickImgList: [], // 点击放大图片列表
				result: [],
				priceList: [],
				specList: [],
				aloneList: [],
				personPop: [],
				goodsList: [], // 拼团价格
				shopInfo: {}, // 商家信息
				video: '',
				imgapi: '',

				loading: true,
				skeleton: [
					'card-lg',
					'line*2',
					40,
					'line*2',
					'card-lg',
				], //骨架屏

				showPopup: false, //弹窗
				showPopupAlone: false, //单独买弹窗
				popHeight: '80vh', //弹窗高度


				discountPrice: 0,
				peopleCount: 0,
				originPrice: null,
				hasSpec: 0,
				speicArr: [],
				numArr: [],
				buyArr: [{
					text: "门店自提",
					value: 0,
				}, {
					text: "快递配送",
					value: 1,
				}, {
					text: '专员配送',
					value: 3
				}], // 购买方式
				people: null,
				discount: null,
				alone: false,
				Hei: "", //这是swiper要动态设置的高度属性
				swiperHeight: '',

				specId: null,
				priceId: null,

				// 人滑动
				swiperPeople: 0,
				buyCurrent: "",
				// 选择
				value: '',
				params: {
					hasSpec: 0, //有无规格
					specSelect: 0, //选中规格
					hasBuyUnit: 0, //有无可选数量
					numSelect: 0, //选中可选数量
					packBuy: -1, // 包邮、自提 选择   1:快递   0:自提
					hasFreeShipp: 0, //是否包邮   1:包邮   -1:不包邮
					minPrice: 0, //最低价格
					showPrice: 0, //展示价格
					originalPrice: 0, //原价
					showTit: 0, //消费提示文字  1:显示最大优惠  -1:展示基础优惠
					count: 0, // 数量
					maxDiscounts: 0, //最大优惠价格
					disSpec: 0, //规格禁用  1可以  -1禁用
					returnMax: 0, //最大返现
					nowGear: 0, //当前档位
					nowReturn: 0, //当前返现
				},
				specNumObj: {}, //规格数量改变

				// 用户所在区域是否支持配送  0: 没有定位 1: 支持 2: 不支持
				hasArea: 0,

				// 满足当前挡位需要的数量
				checkNowDiscountsNum: 0,
			}
		},
		//分享
		onShareAppMessage(res) {
			let usId = uni.getStorageSync("usId")
			let route = this.$mp.page.route;
			return {
				title: '拼单返现💴火热进行中，快来凑单返现吧~', //转发标题
				path: route + `?&parentId=${uni.getStorageSync("usId")}&itemId=` + this.itemId
			}
		},
		onShow() {
			this.showPopup = false
			this.showPopupAlone = false
			this.item.alone = false

			if (uni.getStorageSync("bulk")) {
				this.params = JSON.parse(uni.getStorageSync("bulk"))
			}
		},

		onLoad(e) {
			if (e.parentId != "" && e.parentId != undefined) {
				e.id = e.itemId
				uni.setStorageSync("parentId", e.parentId)
			} else {
				this.itemId = e.id
			}
			this.getList(e)
			this.imgapi = this.$reqConfig.URLIMAGE
		},

		methods: {
			goEvaList() {
				uni.navigateTo({
					url: "/pageA/evaList/evaList?id=" + this.item.id + "&type=" + 4
				})
			},
			// 判断商品配送区域是否在用户区域内
			goodsAreaHasUser(id) {
				let dw = uni.getStorageSync("dingwei");
				if (dw === null || typeof dw === "undefined" || dw == "") {
					this.hasArea = 0;
					return
				}
				let _t = this;
				this.$axios({
					url: `user/public/goodsAreaHasUser`,
					method: 'post',
					data: {
						lng: dw.longitude,
						lat: dw.latitude,
						goodsId: id
					}
				}).then((res) => {
					if (res.code !== 0) {
						return
					}
					_t.hasArea = res.result ? 1 : 2
					if (_t.hasArea !== 1) {
						_t.buyArr.forEach(e => {
							if (e.value === 3) {
								e.disable = true
							}
						})
					}
				})
			},
			// 底部栏按钮
			onClick(e) {
				if (e.index == 1) {
					console.log(this.item)
					let id = uni.getStorageSync("usId")
					uni.navigateTo({
						url: '../../pages/HM-chat/User-Chat?id=' + id + '&sendid=' + this.item.merchantId +
							'&title=' + this.shopInfo.storeName + "&avatar=" + this.shopInfo.storeAvatar
					})
				}
			},
			buttonClick(e) {
				this.tzwoyaozhongOrder()
			},


			getList(e) {
				console.log("分享进来的", e)
				//请求
				this.$axios({
					url: `user/public/groupGoods/detail`,
					method: "post",
					data: {
						id: e.id
					}
				}).then((res) => {
					// 骨架屏取消
					this.loading = false;
					// 基本信息处理
					this.buyCurrent = res.result.current
					this.orderList = res.result.orderList
					this.item = res.result.merchantGroupGoods
					if (this.item.video) {
						this.video = this.$reqConfig.URLIMAGE + this.item.video
					}					
					if (this.item.content.indexOf(this.$reqConfig.URLIMAGE) == -1) {
						this.item.content = this.item.content.replace(/\<img src="/gi,
							'<img src=' + '\"' + this.$reqConfig.URLIMAGE)
					}
					this.item.overview = this.item.overview.trim()
					let imgarr = JSON.parse(this.item.img)
					let newimgarr = []
					imgarr.forEach(item => {
						newimgarr.push(this.$reqConfig.URLIMAGE + item)
					})
					this.imgData = newimgarr
					this.params.hasSpec = this.item.hasSpec
					this.params.unit = this.item.unit
					this.params.hasFreeShipp = this.item.hasFreeShipp

					let goods = res.result.merchantGroupGoods;
					let s = goods.type.toString();
					// console.log("商品支持的收货方式 :  " + typeof s);
					if (s === '2' || s === '310') {
						this.goodsAreaHasUser(e.id);
					} else {
						let tArr = [];
						if (s.includes('0')) {
							tArr.push(this.buyArr[0])
						}
						if (s.includes('1')) {
							tArr.push(this.buyArr[1])
						}
						if (s.includes('3')) {
							this.goodsAreaHasUser(e.id);
							tArr.push(this.buyArr[2])
						}
						this.buyArr = tArr;
						// console.log("支持的收货方式 :" , this.buyArr)
					}

					// 运费模板
					if (this.item.freightId != -1) {
						this.params.freightId = this.item.freightId
					}

					// 处理可选数量
					if (this.item.buyUnit !== "" && this.item.buyUnit !== null && typeof this.item.buyUnit !==
						"undefined") {
						console.log("可选数量 :", this.item.buyUnit)
						this.numArr = this.dealNum(this.item.buyUnit, this.item.unit)
						this.numArr = this.dealSort(this.numArr, "value")
						this.params.hasBuyUnit = 1
					}

					// 拼团价格
					this.goodsList = res.result.groupGoodsPrices
					// 排序
					this.goodsList = this.dealSort(this.goodsList, "successGear")

					let arr = this.goodsList.map(val => val.discountPrice)
					console.log('arr', arr)
					this.params.showPrice = Math.min.apply(Math, arr)
					this.params.minPrice = this.params.showPrice
					this.$set(this.params, "originalPrice", this.item.originalPrice)

					// 商家信息
					this.shopInfo = res.result.shopInfo

					// 规格信息
					this.specList = res.result.specList
					if (this.specList) {
						this.speicArr = this.dealSpec(this.specList)
					}
					this.evaList = res.result.eva
					this.rate = res.result.rate
					// this.params.returnMax = this.finMaxRet(this.goodsList)
					this.params.returnMax = res.result.maxNumber
					uni.setStorageSync("bulk", JSON.stringify(this.params))
					//分享进来的，渲染完成后判断是否登录过，没有登录就跳去登录
					let token = uni.getStorageSync("token")
					let avatarUrl = uni.getStorageSync("avatarUrl")
					if (!token || !avatarUrl) {
						uni.navigateTo({
							url: "../../pages/mine/loginPage"
						})
					}
				})
			},
			// 查找最大返现
			// finMaxRet(list) {
			// 	let price = null,
			// 		arr = [],
			// 		max = null
			// 	// 有规格
			// 	if (this.params.hasSpec == 1) {
			// 		console.log(list);
			// 		arr = list.map(val => val.discountPrice)
			// 		max = Math.min.apply(Math, arr)
			// 		// console.log(max);
			// 		let item = list.find(val => val.discountPrice == max)
			// 		let obj = this.specList.find(val => val.id == item.specId)
			// 		// console.log(2,item);
			// 		// console.log(111,obj);
			// 		price = obj.originPrice - item.discountPrice
			// 	} else {
			// 		arr = list.map(val => val.discountPrice)
			// 		max = Math.min.apply(Math, arr)
			// 		price = this.params.originalPrice * 1 - max * 1
			// 	}
			// 	return price
			// },

			// 处理排序
			dealSort(arr, prop = undefined) {
				if (prop) {
					for (var i = 0; i < arr.length - 1; i++) {
						//获取第二个值，数组长度减去第一个然后再减自身长度
						for (var j = 0; j < arr.length - i - 1; j++) {
							if (arr[j][prop] > arr[j + 1][prop]) {
								var num = arr[j];
								arr[j] = arr[j + 1];
								arr[j + 1] = num;
							}
						}
					}
				}

				return arr
			},

			// 处理规格
			dealSpec(arr) {


				let arr1 = []
				arr.map(val => {
					arr1.push({
						text: val.describe,
						value: val.id,
						remark: val.remark,
						originPrice: val.originPrice,
						score: val.score,
						disable: val.score <= 0 && val.score != -1 ? true : false,
					})
				})
				return arr1
			},
			// 处理可选数量 
			dealNum(buyUnit, unit) {
				let arr = buyUnit.split(",")
				let arr1 = []
				arr.map(val => {
					arr1.push({
						text: val + unit,
						value: val
					})
				})
				return arr1
			},
			// 导航
			handleMapLocation() {
				if (!this.item.selfMentionAddress) {
					uni.showToast({
						title: "商家未填地址",
						icon: "none"
					})
					return
				}

				uni.showLoading({
					title: "加载中"
				})
				console.log('进入导航')

				//  经纬度暂时写死，后面介入数据
				let {
					latitude,
					longitude
				} = uni.getStorageSync("dingwei")
				let address = this.item.selfMentionAddress
				// 获取定位信息
				uni.getLocation({
					type: 'wgs84', //返回可以用于uni.openLocation的经纬度
					// 用户允许获取定位
					success: function(res) {
						console.log(res, '经纬度===>')
						if (res.errMsg == "getLocation:ok") {
							console.log(latitude)
							console.log(longitude)
							uni.openLocation({
								// 传入你要去的纬度
								latitude: latitude,
								// 传入你要去的经度
								longitude: longitude,
								// 传入你要去的地址信息 不填则为空
								address: address,
								// 缩放大小
								scale: 10,
								success: function() {
									uni.hideLoading()
									console.log('成功的回调success');
								}
							});
						}
					},
					// 用户拒绝获取定位后 再次点击触发
					fail: function(res) {
						uni.hideLoading()
						console.log(res)
						if (res.errMsg == "getLocation:fail auth deny") {
							uni.showModal({
								content: '检测到您没打开获取信息功能权限，是否去设置打开？',
								confirmText: "确认",
								cancelText: '取消',
								success: (res) => {
									if (res.confirm) {
										uni.openSetting({
											success: (res) => {
												console.log('确定');
											}
										})
									} else {
										console.log('取消');
										return false;
									}
								}
							})
						}
					}
				});
			},
			changePeople(e) {
				this.swiperPeople = e.detail.current
			},

			getValue(arr, describe) {
				let newArr = arr.map(item => item[describe])
				return Array.from(new Set(newArr))
			},
			unique(arr, key) {
				const res = new Map();
				return arr.filter((arr) => !res.has(arr[key]) && res.set(arr[key], 1))
			},

			goDetail() {
				let _t = this;
				if (this.params.count == 0) {
					uni.showToast({
						title: '请选择购买数量',
						duration: this.duration,
						icon: "none"
					});
					return
				}
				if (this.params.specSelect == 0 && this.params.hasSpec == 1) {
					uni.showToast({
						title: '请选择规格',
						duration: this.duration,
						icon: "none"
					});
					return
				}
				if (this.params.disSpec == -1) {
					uni.showToast({
						title: '该规格库存数量不足,请挑选其他规格',
						duration: this.duration,
						icon: "none"
					});
					return
				}

				if (this.params.packBuy == -1) {
					uni.showToast({
						title: '请选择购买方式',
						duration: this.duration,
						icon: "none"
					});
					return
				}

				if (this.params.packBuy === 3 && this.hasArea !== 1) {
					uni.showToast({
						title: _t.hasArea === 0 ? "您还没有定位不支持配送" : "您目前不在配送区域内",
						duration: this.duration,
						icon: "none"
					});
					return
				}

				this.params = {
					...this.params,
					title: this.item.title,
					avatar: this.item.avatar,
					groupGoodsId: this.item.id,
				}
				console.log("this.params.packBuy: ",this.params.packBuy);
				let params = JSON.stringify(this.params)
				let shopInfo = JSON.stringify(this.shopInfo)
				uni.redirectTo({
					url: `./bulkOrder?params=${params}&shopInfo=${shopInfo}`
				});
			},

			// 打电话
			callphone() {
				uni.makePhoneCall({
					phoneNumber: this.shopInfo.phone //仅为示例
				});
			},
			// 点击图片放大
			clickImg(e) {
				wx.previewImage({
					urls: this.imgData, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current: e.currentTarget.dataset.src, // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
			},
			// 数量加
			add(e) {
				/* if (this.params.numSelect != 0) {
					this.params.count += Number(this.params.numSelect)
				} */
			},
			// 数量减
			minus(e) {
				/* if (this.params.numSelect != 0) {
					this.params.count -= Number(this.params.numSelect)
					if (this.params.count <= 0) {
						this.params.count = 0
					}
				} */
			},
			// 当前数量
			count(e) {
				console.log("当前值", e);
				console.log("当前已下单数量 remark : ", this.item.remark)
				this.params.count = e
				if (this.params.hasSpec != 1) {
					// 无规格
					this.params.showTit = -1 //未到达最大优惠提示
					this.judgeTit()
				} else {
					// 有规格
					console.log("当前规格 :", this.params.specSelect)
					if (this.params.specSelect === 0) {
						return
					}
					this.params.showTit = -1 //未到达最大优惠提示
					this.specNumChange(e)

				}
				this.judgeScore()

				if (e == 0) {
					this.params.showTit = 0 //撤销提示
				}
			},
			// 处理无规格 提示展示
			judgeTit() {
				this.params.showTit = -1 //未到达最大优惠提示
				// this.item.remark  = 1199//测试 价格
				// this.item.inventory = 1//测试 库存

				// 排序
				let list = this.goodsList.sort((a, b) => b.successGear - a.successGear)
				// 最大档位
				let maxNumObj = this.goodsList[0]
				// this.params.showTit = 1 //到达最大优惠提示
				let num = 0,
					index = null
				if (this.params.numSelect == 0) {
					// 没选数量/重量
					num = this.params.count
				} else {
					// 有可选数量
					num = (this.params.count * this.params.numSelect * 1)
				}
				console.log('数量', num);

				if (this.item.hasSpec === -1) {
					if (this.item.inventory != -1 && this.item.inventory < num) {
						this.params.disSpec == -1
						this.isDiscounts = false
						uni.showToast({
							title: '该商品库存数量不足',
							duration: this.duration,
							icon: "none"
						});
						return
					}
				}
				this.isDiscounts = true


				this.params.disSpec == 1
				// 当前选中数量加上当前已下单数量进行判断
				num += this.item.remark * 1
				let obj = this.goodsList.find((val, i) => {
					index = i
					return num >= val.successGear
				})
				console.log("当前达到的优惠挡位 :  ", obj)
				if (!obj) {
					// 无档位
					this.params.showPrice = this.item.originalPrice
					this.params.poorNum = this.goodsList[this.goodsList.length - 1].successGear - num
					this.params.backMoney = this.item.originalPrice - this.goodsList[this.goodsList.length - 1]
						.discountPrice

				} else {
					if (maxNumObj.successGear != obj.successGear) {
						// 不是最大档位
						this.params.showPrice = obj.discountPrice
						this.params.poorNum = this.goodsList[index - 1].successGear - num
						// !!!!!!!!!!!!!!!!!!!!   下一档位价格 - 当前档位价格
						this.params.backMoney = obj.discountPrice - this.goodsList[index - 1].discountPrice
						//  当前返现
						if (this.goodsList[index + 1]) {
							this.params.nowReturn = this.goodsList[index + 1].discountPrice - this.goodsList[index]
								.discountPrice
						} else {
							this.params.nowReturn = this.item.originalPrice - this.goodsList[index].discountPrice
						}
					} else {
						// 最大档位
						console.log("最大档位");
						this.params.showTit = 1 //到达最大优惠提示
						// this.params.showPrice = maxNumObj.discountPrice
						this.params.maxDiscounts = this.item.originalPrice - maxNumObj.discountPrice
						this.params.nowReturn = this.item.originalPrice - maxNumObj.discountPrice
					}
					this.params.showPrice = this.goodsList[index].discountPrice
					// 当前档位
					this.params.nowGear = this.goodsList[index].successGear
				}


				if (num == 0) {
					// 取消提示
					this.params.showTit = 0
					this.params.nowGear = 0
					this.params.nowReturn = 0
				}
				// //如果当前购买数小于最低档位那么赋值为原价
				let arra = this.goodsList.map(val => val.successGear)
				let minSuccessGear = Math.min.apply(Math, arra)
				this.params.numSelect = this.params.numSelect == "" || this.params.numSelect == undefined ? 1 : this.params
					.numSelect
				let total = this.params.numSelect * this.params.count
				console.log('beforCurrent', this.buyCurrent)
				let current = this.buyCurrent + total
				console.log('total', total)
				console.log('numS', this.params.numSelect)
				console.log('count', this.params.count)
				console.log('current', current)
				if (current < minSuccessGear) {
					this.params.showPrice = this.item.originalPrice
				}
			},
			// 判断库存
			judgeScore() {
				// 禁用
				let num = 0
				if (this.params.specSelect != 0) {
					// 有规格
					// this.speicArr[0].score = 2 //测试
					let i = this.speicArr.findIndex(val => val.value == this.params.specSelect)
					if (this.speicArr[i].score == -1) {
						this.params.disSpec = 1
						this.isDiscounts = true;
						return
					}
					if (this.params.numSelect != 0) {
						// 有可选数量
						num = this.params.numSelect * this.params.count
					} else {
						// 没有可选数量
						num = this.params.count
					}

					this.speicArr[i].disable = this.speicArr[i].score < num
					if (this.speicArr[i].disable) {
						this.params.disSpec = -1
						this.params.showTit = 0
					} else {
						this.params.disSpec = 1
						this.isDiscounts = true;
					}
				} else {
					// 无规格
					// this.item.inventory = 2  //测试
					if (this.item.inventory == -1) return
					let flg = null
					// 无规格
					if (this.params.numSelect != 0) {
						// 有可选数量
						num = this.params.numSelect * this.params.count
					} else {
						// 没有可选数量
						num = this.params.count
					}
					console.log("无规格当前选中的数量 : ", num, " 当前库存 : {} ", this.item.inventory)

					flg = this.item.inventory < num
					this.params.disSpec = flg ? -1 : 1
				}
				if (this.params.disSpec == -1) {
					uni.showToast({
						title: '该商品库存数量不足',
						duration: this.duration,
						icon: "none"
					});
					return
				}
			},
			//修改实际数量
			numSelect(e) {
				if (e.detail.data.length == 0) {
					this.params.numSelect = 0
					this.params.count = 0
				}
				this.count(this.params.count);
			},
			// 规格数量变化
			specNumChange(e) {
				console.log("当前选中规格信息 : ", this.specNumObj)
				console.log('e', e)
				if (this.params.specSelect == 0) return
				let num = 0
				let index = null // 当前档位索引
				let obj = this.specNumObj.specObj
				if (this.params.numSelect == 0) {
					// 无可选数量
					console.log("没有可选数量")
					num = e + obj.remark * 1
				} else {
					// 有可选数量
					console.log("有可选数量")
					console.log(obj.remark)
					num = (e * this.params.numSelect * 1) + obj.remark * 1
				}
				// 该规格所有档位
				let allArr = this.specNumObj.allArr
				let maxObj = allArr[0] // 最大档位
				let selectObj = allArr.find((val, i) => {
					index = i
					return num >= val.successGear
				})
				console.log("该规格所有档位", allArr);
				if (selectObj) {
					console.log("有到达档位", selectObj);

					this.$set(this.params, "showPrice", selectObj.discountPrice)
					if (allArr[index - 1]) {
						// 最近的档位
						this.params.poorNum = allArr[index - 1].successGear - num
						// this.params.backMoney = selectObj.discountPrice - allArr[index - 1].discountPrice
						this.params.backMoney = this.specNumObj.specObj.originPrice - allArr[index - 1].discountPrice

						if (allArr[index + 1]) {
							console.log("有上一档位"); // 上一档位 - 当前档位优惠价
							this.params.nowReturn = allArr[index + 1].discountPrice - allArr[index].discountPrice
						} else {
							this.params.nowReturn = obj.originPrice - allArr[index].discountPrice
							console.log("第一档位", this.params.nowReturn);
						}
					}

					if (maxObj.successGear == selectObj.successGear) {
						// 最大档位
						console.log("达到最大挡位")
						this.params.showTit = 1 //到达最大优惠提示
						this.params.maxDiscounts = this.specNumObj.specObj.originPrice - maxObj.discountPrice
						console.log(obj.originPrice + " " + this.params.maxDiscounts)
						this.params.nowReturn = obj.originPrice - maxObj.discountPrice

					}

					// 当前档位

					this.params.nowGear = allArr[index].successGear
					this.checkNowDiscountsNum = allArr[index].successGear - obj.remark;
					console.log("当前挡位需要达到的数量 : ", this.checkNowDiscountsNum)
				} else {
					console.log("无到达档位");
					this.$set(this.params, "showPrice", obj.originPrice)
					this.params.poorNum = allArr[allArr.length - 1].successGear - num
					this.params.backMoney = obj.originPrice - allArr[allArr.length - 1].discountPrice
				}

			},

			// 规格选择
			specSelect(e) {
				console.log("规格选择值 : ", e)
				let obj = e.detail.data
				this.params.specName = obj.text

				// 查到所有档位
				let allArr = this.goodsList.map(val => {
					if (val.specId == obj.value) {
						return val
					}
				})
				allArr = allArr.filter(res => {
					return res != undefined
				})
				allArr.sort(function(a, b) {
					return b.successGear - a.successGear
				})

				this.specNumObj = {
					...this.specNumObj,
					specObj: obj,
					allArr: allArr,
				}
				return
				// 当前档位价格
				if (selectObj) {
					console.log("有到达档位", selectObj);

					this.$set(this.params, "showPrice", selectObj.discountPrice)
					if (allArr[index - 1]) {
						this.params.poorNum = allArr[index - 1].successGear - obj.remark
						this.params.backMoney = selectObj.discountPrice - allArr[index - 1].discountPrice
					}

					if (maxObj.successGear == selectObj.successGear) {
						this.params.showTit = 1 //到达最大优惠提示
						this.params.maxDiscounts = obj.originPrice - maxObj.discountPrice
					}
				} else {
					console.log("无到达档位");
					this.$set(this.params, "showPrice", obj.originPrice)

					this.params.poorNum = allArr[allArr.length - 1].successGear - obj.remark
					this.params.backMoney = obj.originPrice - allArr[allArr.length - 1].discountPrice
				}

			},
			// 配送选择   -1:邮递  1：快递  
			buySelect(e) {
				if (e.detail.value === 3) {
					this.isMethodPrompt = true
				} else {
					this.isMethodPrompt = false;
				}
				// this.params.packBuy = e.detail.value == 0 ? 1 : -1
			},

			selectPop3(e) {
				this.discount = e.detail.value
				this.aloneList.map(val => {
					if (val.describe == this.discount) {
						this.discountPrice = val.originPrice
					}
				})
			},

			remove(arr, item) {
				for (var i = 0; i < arr.length; i++) {
					if (arr[i] == item) {
						//从i出开始删除1个元素
						arr.splice(i, 1);
						i--;
					}
				}
				return arr;
			},
			// 单独购买
			tzwoyaozhaiOrder() {
				if (this.params.hasSpec != 1) {
					this.item.alone = true
					let item = encodeURIComponent(JSON.stringify(this.item))
					let shopInfo = encodeURIComponent(JSON.stringify(this.shopInfo))
					uni.navigateTo({
						url: `./bulkOrder?item=${item}&shopInfo=${shopInfo}`
					});
				} else {
					this.showPopupAlone = true
				}

			},
			// 发起拼团
			tzwoyaozhongOrder() {
				this.alone = true
				this.showPopup = true
			},
			goList() {
				uni.navigateTo({
					url: `./bulkList`
				})
			},
			onEditorReady() {
				// #ifdef MP-BAIDU
				this.editorCtx = requireDynamicLib('editorLib').createEditorContext('editorId');
				// #endif

				// #ifdef APP-PLUS || H5 ||MP-WEIXIN
				uni.createSelectorQuery().select('#editor').context((res) => {
					this.editorCtx = res.context
				}).exec()
				// #endif
			},
			undo() {
				this.editorCtx.undo()
			},

			addCart: function(item) {

				if (item.count >= 0) {
					item.count++
					this.goods.forEach((good) => {
						good.foods.forEach((food) => {
							// 根据名字添加购物车,实际环境根据需要更改
							if (item.name == food.name) {
								food.count = item.count
								// this.catrgoryList.push(item)
								// console.log('列表',this.catrgoryList)
							}
						})
					})
				} else {

					this.goods.forEach((good) => {
						good.foods.forEach((food) => {
							if (item.name == food.name)
								Vue.set(food, 'count', 1)
						})
					})
				}
			},
			decreaseCart(item) {
				this.catrgoryList.push(item)
				console.log('列表', this.catrgoryList)
				if (item.count) {
					item.count--
					this.goods.forEach((good) => {
						good.foods.forEach((food) => {
							if (item.name == food.name)
								food.count = item.count
						})
					})
				}
			},

		}
	}
</script>

<style scoped lang="scss">
	.topIntro {
		border-radius: 15rpx;
		height: 130rpx;
		position: absolute;
		background-color: #fff;
		top: -50rpx;
		width: 90%;
		display: flex;
		overflow: hidden;
		box-shadow: 0 7rpx 13rpx #a0d128;
		transition: top .5s;

		.left {
			padding: 20rpx;
			padding-left: 20rpx;
			font-size: 40rpx;
			font-weight: bold;
			color: #fff;
			width: 70%;
			background: linear-gradient(45deg, #a0d128, $theme-back);
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.leftBottom {
				font-size: 25rpx;
				font-weight: normal;
			}
		}

		.right {
			width: 30%;
			color: $theme-back;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0rpx;

			.rightTop {
				font-size: 25rpx;
			}

			.rightBot {
				font-size: 25rpx;

				text {
					display: inline-block;
					background-color: #a0d128;
					color: #fff;
					font-weight: bold;
					font-size: 35rpx;
					padding: 5rpx;
					border-radius: 10rpx;
					margin-right: 5rpx;
				}
			}
		}
	}

	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}



	.color {
		color: $theme-buy-color !important;
	}

	.peopleSwiper {
		height: 200rpx;
		// margin-bottom: 40rpx;

		.imgView {
			border: 2rpx solid #EEEEEE;
			margin-right: 10rpx;
		}

		.contRight {
			.name {
				text-align: center;
				margin-bottom: 10rpx;
			}
		}
	}

	.overview {
		display: inline-block;
		vertical-align: top;
		margin-left: 10rpx;
		width: 85%;
		margin-bottom: 20rpx;
		color: #00000082;
	}



	.bulk {
		border: 1px solid #EEEEEE;
		box-shadow: 0 0 13rpx 10rpx #eee;
		border-radius: 15rpx;
		padding: 25rpx;
		margin-bottom: 60rpx;
	}

	.bulkTit {
		display: flex;
		justify-content: space-between;
		font-size: 32rpx;
		border-bottom: 1px solid #eee;
		padding-bottom: 20rpx;
		margin-bottom: 15rpx;

		.titTop {

			text {
				color: #f00;
				font-weight: bold;
				font-size: 35rpx;
			}
		}
	}

	.bulkTit .titLeft {
		font-weight: bold;
	}

	.bulkCont {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.bulkCont {
		.contLeft {
			image {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				vertical-align: middle;
			}

			.adress {
				text {
					display: inline-block;
					width: 380rpx;
					vertical-align: top;
					margin-left: 12rpx;
				}
			}
		}
	}

	.bulk .textSize {
		font-size: 32rpx;
		color: #00000082;
		position: relative;

		.image {
			position: absolute;
		}
	}


	.bulkCont .contRight {
		button {
			height: 60rpx;
			line-height: 60rpx;
			font-size: 30rpx;
			color: #fff;
			background: linear-gradient(45deg, #7bba0d, #a9ec28);
			border-radius: 50rpx;
		}

		.btn {
			background: transparent;
			color: #7bba0d;
			border: 2rpx solid;
		}

		text {
			color: #F00;
			font-weight: bold;
			font-size: 35rpx;
		}
	}


	.bottomCont {
		background-color: #fff;
	}

	.bottomCont .cont {
		padding: 130rpx 35rpx 1rpx;
		position: relative;
	}

	.line {
		height: 30rpx;
		background-color: #eee;
	}

	.contenerBox {
		width: 100%;
		height: calc(100vh - 10rpx);

	}

	.swiper {

		width: 100%;
		height: 100%;
	}

	.uni-margin-wrap {
		height: 39%;
	}

	.swiper-item {
		display: block;
		line-height: 300upx;
		text-align: center;
	}

	.swiperimg {
		width: 100%;
		height: 100% !important;
	}

	.biaotiBox {
		text-align: left;
		width: 700rpx;
		font-weight: bold;

	}

	.informationBox2 {
		height: 100%;
		border-radius: 15rpx;
		width: 700rpx;
		background-color: #fff;
	}

	.pricetiBox {
		width: 750rpx;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
	}

	.biaotiTitle {
		background-color: #4CD964;
		color: #fff;
		border-radius: 10rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
	}

	.food-price {
		color: #f01414;
		font-size: 16px;
	}

	.evaluationBox {
		padding: 15rpx 0;
		width: 750rpx;
		background-color: #fff;
	}

	.icon_next {
		margin-top: 7rpx;
		height: 30rpx;
		width: 30rpx;
	}

	.avatarUrl {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		background: #c4c4c4;
	}

	.name {
		margin-left: 15rpx;
	}

	.moreBox {
		height: 60rpx;
		line-height: 60rpx;
	}

	.evaluationImg {
		margin-top: 15rpx;
		height: 150rpx;
		width: 150rpx;
		border-radius: 15rpx;
	}

	.shopDetails {
		padding-top: 20rpx;
		width: 750rpx;
		height: 400rpx;
		background-color: #fff;
		margin-bottom: 150rpx;
	}



	.shopDetailsimg {
		width: 750rpx;
		height: 100%;
	}



	.shopBottomText {
		font-size: 22rpx;
	}

	.sharebox {
		width: 150rpx;
		background-color: #00A0DC;
		text-align: center;
		color: #fff;
		flex: 1;
		height: 100%;
		border-radius: 0;
	}

	.zhaibox {
		width: 180rpx;
		text-align: center;
		color: #fff;
		background-color: #e2ffb3;
		flex: 2;
		height: 100%;
		color: #86cc14;
		display: flex;
		flex-direction: column;
		font-size: 35rpx;
	}

	.collectionimg {
		width: 40rpx;
		height: 40rpx;
	}

	.editorBox {
		padding: 10px;
	}

	#editor {
		width: 100%;
		height: 300px;
		background-color: #CCCCCC;
	}

	.shopBottomBox {
		position: fixed;
		bottom: 0;
		height: 100rpx;
		line-height: 100rpx;
		width: 750rpx;
		background-color: #fff;
	}

	.priceTit {
		color: #6d6d6d;
		font-size: 40rpx;
		font-weight: bold;
		margin: 20rpx 0 30rpx;
		display: flex;
		justify-content: space-between;
	}

	.priceTit .sale {
		font-size: 25rpx;
		text-decoration: line-through;
		color: #e3e3e3;
		margin-left: 20rpx;
		font-weight: normal;
	}

	.desc {
		padding: 20rpx;
	}

	.topPop {
		height: 180rpx;
	}

	.topPop image {
		position: absolute;
		width: 150rpx;
		height: 150rpx;
		border: 2rpx solid #a0e223;
		border-radius: 20rpx;
	}

	.topPop .right {
		margin-left: 180rpx;
		color: $theme-buy-color;
		font-weight: bold;
		font-size: 40rpx;

		text {
			font-size: 30rpx;
		}

		.introTit {
			font-size: 28rpx;
			color: #666;

			.introColor {
				color: $theme-buy-color;
				font-size: 35rpx;
			}
		}

		.origin {
			font-weight: normal;
			text-decoration: line-through;
			color: #c4c4c4;
			margin-left: 10rpx;
		}

	}


	.selectCont {
		margin-bottom: 20rpx;

		.selectName {
			margin: 20rpx 0;
			font-size: 30rpx;
			color: #666;
		}

		.tagSelect {
			display: flex;
			flex-direction: row;
			align-items: center;

			.packIntro {
				background-color: $theme-back;
				margin-right: 10px;
				padding: 5px 10px;
				color: #fff;
				border-radius: 3px;

				font-size: 25rpx;
				height: 25rpx;
				line-height: 25rpx;
				border: none !important;
			}

			.btn {
				color: #fff;
				background: linear-gradient(45deg, #7bba0d, $theme-back);
				border-radius: 50rpx;
			}
		}
	}

	/deep/.checklist-box {
		height: 25rpx;
		border: none !important;
	}

	.btnPop {
		border-radius: 100rpx;
		margin-top: 35rpx;
		background-color: #86cc14;
		position: fixed;
		width: 95%;
		bottom: 30rpx;
	}
</style>
